package com.yc.fruitmarket.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.fruitmarket.biz.pvalBiz;
import com.yc.fruitmarket.biz.impl.pvalBizImpl;

@WebServlet("/pvalController/*")
public class pvalController extends BaseServlet {
	private pvalBiz pb = new pvalBizImpl();
	
	//获取pid商品的星级
	public void getstarL(HttpServletRequest req, HttpServletResponse resp) {
		String pid = req.getParameter("pid");
		double a = pb.getstarL(pid);
		this.send(resp, a);
	}
	
	//条件查询
	public void byassess(HttpServletRequest req, HttpServletResponse resp) {
		String pname = req.getParameter("pname");
		String pid = req.getParameter("pid");
		String starnum = req.getParameter("starnum");
		String oid = req.getParameter("oid");
		String start = req.getParameter("start");
		String end = req.getParameter("end");
		String currentPage4 = req.getParameter("currentPage4");
		String pagesize = req.getParameter("pagesize");
		List<Map<String, String>> list = pb.byassess(pname, pid, starnum, oid, start, end, currentPage4, pagesize);
		this.send(resp, list);
	}
	
	//查询商品评论
	public void getassess(HttpServletRequest req, HttpServletResponse resp) {
		List<Map<String, String>> list = pb.getassess();
		for(Map<String, String> map : list) {
			map.put("value", map.get("pname"));
		}
		this.send(resp, list);
	}
	
	//查出商品评论信息
	public void getPval(HttpServletRequest req, HttpServletResponse resp) {
		String pid = req.getParameter("pid");
		if("".equals(pid) || pid == null) {
			return;
		}
		List<Map<String, String>> list = pb.getPval(pid);
		if(list.size()>0) {
			this.send(resp, list);
		}else {
			return;
		}
	}
	//对单个商品评论
	public void sendPval(HttpServletRequest req, HttpServletResponse resp) {
		String uid = req.getParameter("uid");
		String pid = req.getParameter("pid");
		String pval = req.getParameter("pval");
		String rating = req.getParameter("rating");
		String oid = req.getParameter("oid");
		if("".equals(pval)||"".equals(pid)||"".equals(uid)||"".equals("oid")) {
			return;
		}else {
			int result = pb.sendPval(uid, pid, pval, rating, oid);
			if(result > 0) {
				this.send(resp, result);
			}else {
				this.send(resp, -1);
			}
		}
	}
	
}
